﻿using System.Collections.Generic;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using Jinndev.UI;

namespace Jinndev {

    /// <summary>
    /// 地图编辑器中的瓦片选项
    /// </summary>
    public class MapTileItemUI : BaseUIBehaviour {

        public System.Action<MapTileItemUI> onClick;

        public RawImage image;
        public Text textID;
        public Text textInfo;
        public GameObject border;

        public TileConfig config;
        public int index;

        public void Refresh(TileConfig config, int index, bool selected) {
            this.config = config;
            this.index = index;

            textID.text = config.id;
            textInfo.text = $"({config.anchor.x}, {config.anchor.y}) H={config.height}";
            image.texture = MapUtil.LoadTexture(config);
            Selected = selected;
        }

        public void OnClick() {
            onClick?.Invoke(this);
        }

        public bool Selected {
            set {
                border.SetActive(value);
            }
        }

    }

}
